#ifndef __SERIAL_H__
#define __SERIAL_H__


#include "common.h"

#define SERRECBUF_FLOWCTRL_UP 18
#define SERRECBUF_FLOWCTRL_LOW 6

#define SERIALTIMERID 1
#define SERIALTIMERINTID TF1_VECTOR
#define SERIALINTERRUPTID SIO_VECTOR

#define POSPLUS(pos,total) pos=(pos>=(total-1)?0:pos+1)

void SERIAL_INIT();
void SERIAL_ENABLE();
void SERIAL_DISABLE();
void SERIAL_BAUD_X12(bool enable);
bool SERIAL_ISSENDING();

//for sending
void SERIAL_SEND_S(uchar *pointer);
void SERIAL_SEND_C(uchar ch);
void SERIAL_SEND_CA(uchar *pointer, uchar len);
bool SERIAL_UNSAFE_SEND(uchar *pointer, uchar len);

//for receiving
bool SERIAL_TRY_GET_C(uchar tryCount, uchar *pointer);
bool SERIAL_TRY_GET_CA(uchar tryCount, uchar *pointer, uchar len);
bool SERIAL_UNSAFE_GET(uchar *pointer, uchar len);
void SERIAL_FLUSH_GET();
typedef void (*serialRecCallback)(uchar len);
void SERIAL_UPDATE_FLOWCTRL();

#ifdef SDCC
void serial(void) interrupt SERIALINTERRUPTID;
#endif

#endif//__SERIAL_H__
